package com.wugui.datax.admin.util;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.File;

/****************************************
 *
 *@Author: wangzp
 *@Date: 2023/8/1 周二 13:39
 *@Desc:
 *
 *****************************************/

public class FileConstants {

    public static final String DEFAULT_ALLOWED_EXTENSION = "{" +
            "'file' : 'xls,xlsx'," +
            "'image' : 'jpg,jpeg,png'," +
            "'video' : 'mp4,avi'" +
            "}";

    public static final String DEFAULT_DATASOURCE_TYPE = "{" +
            "'db':'',"+
            "'file':'excel'"+
            "}";
    public static String getFileTypeByName(String fileName){
        String fileType = "";
        JSONObject json = JSON.parseObject(DEFAULT_ALLOWED_EXTENSION);
        for (String key : json.keySet()){
            if (json.getString(key).contains(fileName)){
                fileType = key;
            }
        }
        return fileType;
    }

    public static String getDataSourceType(String datasource){
        String dataSourceType = "db";
        JSONObject json = JSON.parseObject(DEFAULT_DATASOURCE_TYPE);
        for (String key : json.keySet()){
            if (json.getString(key).contains(datasource)){
                dataSourceType = key;
            }
        }
        return dataSourceType;
    }

    public static void main(String[] args) {
        String type = getFileTypeByName("xls");
        System.out.println(type);

        String A = "A";
        String B = A + File.separator + "C";
        System.out.println(B);
    }
}
